home *** CD-ROM | disk | FTP | other *** search
- unit Image2;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, ExtCtrls;
-
- type
- TNewImage = class(TImage)
- private
- FCanvas: TCanvas;
- FBmp: TBitmap;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure WMPaint(var Msg: TWMPaint); message wm_Paint;
- procedure Paint; override;
- end;
-
- procedure Register;
-
- implementation
-
- constructor TNewImage.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- { Can't draw on the TImage canvas - that turns }
- { out to be the bitmap object's canvas }
- FCanvas := TCanvas.Create;
- { Temporary bitmap to cause palette realization }
- FBmp := TBitmap.Create;
- end;
-
- destructor TNewImage.Destroy;
- begin
- FBmp.Free;
- FCanvas.Free;
- inherited Destroy;
- end;
-
- procedure TNewImage.WMPaint(var Msg: TWMPaint);
- begin
- { Identify what the real canvas is }
- FCanvas.Handle := Msg.DC;
- { Do normal stuff, like call Paint }
- inherited;
- { Now forget about it }
- FCanvas.Handle := 0;
- end;
-
- procedure TNewImage.Paint;
- begin
- { Only do new stuff if it is a stretched image }
- if (Picture.Graphic = nil) or not Stretch then
- inherited Paint
- else
- begin
- FBmp.Height := Picture.Height;
- FBmp.Width := Picture.Width;
- FBmp.Canvas.Draw(0, 0, Picture.Graphic);
- FCanvas.StretchDraw(ClientRect, FBmp);
- end
- end;
-
- procedure Register;
- begin
- RegisterComponents('Samples', [TNewImage]);
- end;
-
- end.
-